#include <bits/stdc++.h>

using namespace std;

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution
{
public:
    unordered_set<int> s;
    void f(TreeNode *root)
    {
        if (root == nullptr)
        {
            return;
        }
        f(root->left);
        s.insert(root->val);
        f(root->right);
    }
    bool findTarget(TreeNode *root, int k)
    {
        f(root);
        for (auto e : s)
        {
            if (s.find(k - e) != s.end() && e != k - e)
            {
                return true;
            }
        }
        return false;
    }
};